package homework.day12;

import java.util.*;

public class ProductImpl implements IProduct {
  static   List<Product01> list=new ArrayList<>();
    public ProductImpl(){

    Product01 p1 = new Product01("宝洁","洗手粉",18.5);
    Product01 p2 = new Product01("联合利华","肥皂",4.5);
    Product01 p3 = new Product01("宝洁","牙膏",32.5);
    Product01 p4 = new Product01("宝洁","毛巾",14.5);
    Product01 p5 = new Product01("洁利","洗面奶",26.0);
    Product01 p6 = new Product01("好迪","洗发水",27.5);
    Product01 p7 = new Product01("多芬","沐浴露",38.5);
    Product01 p8 = new Product01("宝洁","洗洁精",3.4);
    list.add(p1);
    list.add(p2);
    list.add(p3);
    list.add(p4);
    list.add(p5);
    list.add(p6);
    list.add(p7);
    list.add(p8);

    }

    @Override
    public void cost() {
        Collections.sort(list);
        Iterator<Product01> iter = list.iterator();

        double cost=0;
        while (iter.hasNext()){
            Product01 p=iter.next();
              cost+=p.getCost();

            System.out.println(p);
        }
        System.out.println("价格"+cost);


    }
}
